package com.yanqu.road.server.cmd.activity.jiuzhou;

import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.activity.jiuzhou.JiuZhouProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.activity.jiuzhou.JiuZhouModule;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.server.protocol.GameProtocol;

@Cmd(code = GameProtocol.S_JIU_ZHOU_GUESS, desc = "九州棋局竞猜")
public class JiuZhouGuessCmd extends AbstractCommand {

    JiuZhouProto.JiuZhouGuessReqMsg reqMsg;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        reqMsg = JiuZhouProto.JiuZhouGuessReqMsg.parseFrom(packet.getBytes());
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        ret = player.getModule(JiuZhouModule.class).guess(reqMsg);
    }

    @Override
    public void sendData(GamePlayer player) {
        if (ret != 0){
            JiuZhouProto.JiuZhouGuessRespMsg.Builder builder = JiuZhouProto.JiuZhouGuessRespMsg.newBuilder();
            builder.setRet(ret);
            player.sendPacket(ClientProtocol.U_JIU_ZHOU_GUESS, builder);
        }
    }
}
